// Copyright (c) 2023 刻BITTER
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.


#pragma once


#include <stdint.h>


namespace oled_basic {

    enum class write_mode : uint8_t {
        cmd,
        non_inverse,
        inverse,
    };
    
    
    template <typename Child>
    struct CommonWriteCmd {
        static void write_cmd(uint8_t cmd) {
            Child::write_byte(cmd, write_mode::cmd);
        }
    };


    template <typename Child>
    struct CommonWriteData {
        static const uint8_t *write_data(const uint8_t *data_ptr, uint8_t len, write_mode mode) {
            while (len--) {
#ifdef ARDUINO
                uint8_t data_byte = pgm_read_byte(data_ptr++);
#else
                uint8_t data_byte = *(data_ptr++);
#endif
                Child::write_byte(data_byte, mode);
            }
            return data_ptr;
        }
    };
    
    template <typename Child>
    struct CommonWriteCmdAndData : public CommonWriteCmd<Child>, public CommonWriteData<Child> {
    
    };

}  // namespace oled_basic